

class Solution {
    public int paintWalls(int[] cost, int[] time) {
        int sum = 0;
        int timeS = 0;
        for(int i=0; i<cost.length; i++){
            sum += cost[i];
            timeS += time[i];
        }
        while(true){
            int j = 0;
            int m = 0;
            for(int i=0; i<cost.length; i++){
                if(m < cost[i]){
                    m = cost[i];
                    j = i;
                }
            }
            timeS -= time[j];
            if(timeS >= 1){
                sum -= cost[j];
                cost[j] = 0;
            }else{
                return sum;
            }
        }
    }
}